Skip to content

OpenGL UI components#52

Open
morganchristiansson wants to merge 3 commits into
Return-To-The-Roots:masterfrom
morganchristiansson:gl2-ui
Open

OpenGL UI components#52
morganchristiansson wants to merge 3 commits into
Return-To-The-Roots:masterfrom
morganchristiansson:gl2-ui

Conversation

@morganchristiansson

Copy link
Copy Markdown
Contributor

Draw all UI components with OpenGL.
Keeps UI component SDL_Surface for a smaller PR but avoids 4K penalty of uploading a 4K 32bit 33MB surface each frame 2GB per second. Only small component surfaces are uploaded each frame.
Splash, main menu and options screens are entirely OpenGL.

Replacing SDL_Surface in each component with OpenGL to be addressed in future PR.
Terrain editor Surf_Map remains 2D/SDL/SGE in this branch.

@morganchristiansson

Copy link
Copy Markdown
Contributor Author

Also I can push this PR all the way replacing the per-component SDL_Surface with OpenGL. It's not hard at all with AI agent. I only left it out of scope for simpler review. Main benefit is already achieved.

@Flamefire

Copy link
Copy Markdown
Member

Draw all UI components with OpenGL.
Keeps UI component SDL_Surface for a smaller PR but avoids 4K penalty of uploading a 4K 32bit 33MB surface each frame 2GB per second. Only small component surfaces are uploaded each frame.
Splash, main menu and options screens are entirely OpenGL.

Can you give a bit more background? This code is old with old design decisions etc. which I don't remember especially as it wasn't written by me.
So a short summary of what and where issues are, how they manifest, what the change actually does and how that solves the problem.

IIRC SDL does use OpenGL as the backend/renderer, so the code alread is "using OpenGL" (to some extent)

@morganchristiansson

Copy link
Copy Markdown
Contributor Author

s25edit doesn't use OpenGL at all.
SDL and SGE is entirely 2D. Software CPU rendering.
Personally I get 1-2fps on 4k display so it's unusable. Idk if it's cause I have 13 year old 4.5GHz quad core i7-4770k CPU and DDR3 RAM and newer CPUs can easier push ~2GB of 32bit pixel data per second @ 60fps.

And say I want to use ctrlButton from libsiedler2 instead of s25edit CButton.
It draws with 3D https://github.com/Return-To-The-Roots/s25client/blob/master/libs/s25main/controls/ctrlButton.cpp#L92-L94

Keep small surface per UI component that is drawn with OpenGL
Avoids big 4K penalty while keeping change small
@morganchristiansson

morganchristiansson commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Hmm this PR is currently really small and nice.

But replacing getSurface() with getTexture() is keeping with 2D blitting patterns, s25client uses Draw() which enables components to draw directly. Much bigger PR tho.
I guess getTexture() is fine tho and gets us most value from least change.
But if Draw() is better than render loop doing getSurface().Draw(), and the UI components should not have both SDL_Surface and Texture, then should just eat the bigger PR now rather than having a follow up after.

And hmm maybe #47 gl2-terrain should really be parallel PR and not on top of this one. It doesn't change UI components at all.

@morganchristiansson

Copy link
Copy Markdown
Contributor Author

Ok I went ahead and implemented Draw() with removed getSurface() and getTexture()

# before:
12 files changed, 143 insertions(+), 78 deletions(-)
# after:
25 files changed, 632 insertions(+), 903 deletions(-)

bigger change but removing 280 lines!

@morganchristiansson morganchristiansson changed the title OpenGL UI (on top of #50 OpenGL backgrounds & cursor) OpenGL UI components Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants